//
//  ProjectViewController.m
//  lcf-newproject
//
//  Created by yangyang on 14-11-24.
//  Copyright (c) 2014年 yang. All rights reserved.
//

#import "ProjectViewController.h"
#import "IndexProjectCell.h"
#import "HeaderSectionView.h"
#import "SettingManager.h"
#import "LCFNetWorkRequest.h"
#import "ProjectDetailViewController.h"
@interface ProjectViewController ()

@property (nonatomic,strong)UITableView * tableView;
@property (nonatomic,strong)NSMutableArray * dataArray;

@end

@implementation ProjectViewController

- (void)viewDidLoad {
    [super viewDidLoad];
#pragma mark - 以后要修改的
    
    [self setNavigationRightBarWithTitle:nil withNormalImageName:@"message.png" withSelectedImageName:nil withAction:@selector(messageBtnClick:)];
    [self uiConfig];
    
    // Do any additional setup after loading the view.
}

-(void)uiConfig{
    self.automaticallyAdjustsScrollViewInsets = NO;
    
    _dataArray = [[NSMutableArray alloc]init];
    _tableView = [self creataTableViewWithFrame:CGRectMake(0, ProjectTabBarHeight, __MainScreen_Width, __MainScreen_Height-__TabBar_Height-ProjectTabBarHeight-44) withTableViewStyle:UITableViewStyleGrouped];
    [_tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
    _tableView.showsVerticalScrollIndicator = NO;
    [_tableView setSeparatorInset:UIEdgeInsetsZero];
    _tableView.backgroundColor = [SettingManager hexStringToColor:@"f3f3f3"];
    [self.view addSubview:_tableView];
    
    NSArray * nameArray = @[@"担保项目",@"消费金融",@"债权交易"];
    NSDictionary * dict = [NSDictionary dictionaryWithObject:nameArray forKey:@"tabBarName"];
    ProjectTopTabBar * tabBar = [[ProjectTopTabBar alloc]initWithFrame:CGRectMake(0, 0, __MainScreen_Width, ProjectTabBarHeight)withTabBarDict:dict];
    tabBar.delegate = self;
    [self.view addSubview:tabBar];
}

-(void)prepareData{
    
    [[LCFNetWorkRequest shareRequestManager]sendAsynchronousRequestDataWithUrl:@"www.baidu.com" parameters:nil requestMethod:LCFRequestGetMethod completionHandle:^(ResponseItem * item) {
        
    } failedHandler:^(NSError *error) {
        
    }];
}


#pragma mark - UITableViewDelegate

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    ProjectDetailViewController * detail = [[ProjectDetailViewController alloc]init];
    [self.navigationController pushViewController:detail animated:YES];
}


-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return ProjectCellHeight;
}

-(CGFloat)tableView:(UITableView *)tableView estimatedHeightForHeaderInSection:(NSInteger)section{
    return 28;
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    HeaderSectionView * view = [[[NSBundle mainBundle]loadNibNamed:@"HeaderSectionView" owner:self options:nil]lastObject];
    view.projectStatusLabel.textColor = [SettingManager hexStringToColor:@"666666"];
    if (section == 0) {
        view.projectStatusLabel.text = @"即将开始";
    }else if(section == 1){
        view.projectStatusLabel.text = @"正在融资";
    }else {
        view.projectStatusLabel.text = @"融资满额";
    }
    return view;
    
}

#pragma mark - UITableViewDataSource

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 3;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (section == 0) {
        return 2;
    }else if(section == 1){
        return 2;
    }else {
        return 3;
    }
}



-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString * cellIde = @"projectCell";
    IndexProjectCell * cell =  [tableView dequeueReusableCellWithIdentifier:cellIde ];
    if (cell==nil) {
        cell = [[[NSBundle mainBundle]loadNibNamed:@"IndexProjectCell" owner:self options:nil]lastObject];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.tradeTypeImageView.image = [UIImage imageNamed:@"xiao.png"];
    cell.projectNameLabel.text = @"客运公司运营车辆";
    cell.earningLabel.text = @"15";
    cell.financinglimitLabel.text = @"1000";
    cell.monthLimitLabel.text = @"12";
    cell.bondingCompanyNameLabel.text = @"北京同益达担保有限公司";
    cell.repayTimeLabel.text = @"2015-10-10";
    [cell createProgressView:0.89];
    
    return cell;
}

#pragma mark - ProjectTopBarDelegate
-(void)customTabBar:(ProjectTopTabBar *)custom didSelectedIndex:(NSInteger)index{
    NSLog(@"index = %ld",(long)index-LCFProjectTabBarTag);
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    self.tableView = nil;
    self.dataArray = nil;
    // Dispose of any resources that can be recreated.
}


-(void)messageBtnClick:(UIButton *)btn{
    NSLog(@"message：以后转为view");
}

@end
